package com.zbkj.admin.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zbkj.dal.base.enums.WithdrawPayTypeEnums;
import com.zbkj.dal.base.enums.WithdrawStatusEnums;
import com.zbkj.dal.common.utils.MoneyUtil;
import com.zbkj.dal.entity.fund.UserWithdrawRecord;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel
public class WithdrawListVO {

    @ApiModelProperty(value = "申请单号", example = "CU369170334556873455064")
    private String withdrawNo;

    @ApiModelProperty(value = "雅识账户", example = "1")
    private String fundAccount;

    @ApiModelProperty(value = "账户名", example = "张三")
    private String accountName;

    @ApiModelProperty(value = "开户行", example = "中国建设银行")
    private String bankName;

    @ApiModelProperty(value = "银行卡号", example = "12020328201")
    private String bankcardNo;

    @ApiModelProperty(value = "申请金额", example = "1000.00")
    private String amount;

    @ApiModelProperty(value = "转账状态", example = "SUCCESS")
    private String status;

    @ApiModelProperty(value = "转账状态描述", example = "转账成功")
    private String statusDesc;

    @ApiModelProperty(value = "转账方式", example = "线下支付")
    private String payType;

    @ApiModelProperty(value = "转账方式描述", example = "线下支付")
    private String payTypeDesc;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "转账创建时间", example = "2024-03-07 00:00:00")
    private LocalDateTime createdTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "转账成功时间", example = "2024-03-07 00:00:00")
    private LocalDateTime finishedTime;

    @ApiModelProperty(value = "转账凭证", example = "http://***/*.jpg")
    private String certificatePath;

    @ApiModelProperty(value = "操作人", example = "李四")
    private String operator;

    public static List<WithdrawListVO> transform(List<UserWithdrawRecord> records) {
        if (CollectionUtils.isEmpty(records)) {
            return new ArrayList<>();
        }
        return records.stream().map(WithdrawListVO::transform).collect(Collectors.toList());
    }

    public static WithdrawListVO transform(UserWithdrawRecord record) {
        WithdrawListVO withdrawListVO = new WithdrawListVO();
        withdrawListVO.setWithdrawNo(record.getWithdrawNo());
        withdrawListVO.setFundAccount(record.getFundAccount());
        withdrawListVO.setAccountName(record.getBankAccountName());
        withdrawListVO.setBankName(record.getBankName());
        withdrawListVO.setBankcardNo(record.getBankcardNumber());
        withdrawListVO.setAmount(MoneyUtil.prettyFormat(record.getWithdrawAmount()));
        withdrawListVO.setStatus(record.getStatus());
        withdrawListVO.setStatusDesc(WithdrawStatusEnums.getDescByCode(record.getStatus()));
        withdrawListVO.setPayType(record.getPayType());
        withdrawListVO.setPayTypeDesc(WithdrawPayTypeEnums.getDescByCode(record.getPayType()));
        withdrawListVO.setCreatedTime(record.getCreateTime());
        withdrawListVO.setFinishedTime(record.getFinishTime());
        withdrawListVO.setCertificatePath(record.getCertificatePath());
        withdrawListVO.setOperator(record.getOperator());
        return withdrawListVO;
    }

}
